<!DOCTYPE html>
<html lang="en">

<head>
    <#include "/lx/admin/components/meta.html" />
    <title>中国大学管理 ${metaTitleSuffix!}</title>
    <#include "/lx/admin/components/stylesheets.html" />
</head>

<body>
    <div id="app">
        <el-container>
            <#assign menuIndex="4-1" />
            <#include "/lx/admin/components/menu.html" />
            <el-container>
                <#include "/lx/admin/components/header.html" />
                <el-main>
                    <template>
                        <el-row>
                            <el-col :span="12">
                                <div class="title theme-color1">中国大学管理</div>
                            </el-col>
                            <el-col :span="12">
                                <div class="operations">
                                    <el-button type="success" size="small" @click="add"><i class="el-icon-plus"></i>添加</el-button>
                                </div>
                            </el-col>
                        </el-row>
                        <div class="search">
                            <el-input v-model="keyword" style="width: 220px;" clearable placeholder="请输入关键字"></el-input>
                            <el-button @click="onSearch"><i class="el-icon-search"></i>筛选</el-button>
                        </div>
                        <el-table ref="multipleTable" :data="list" tooltip-effect="dark" :stripe='true' style="width: 100%">
                            <el-table-column prop="name" label="名称" show-overflow-tooltip>
                            </el-table-column>
                            <el-table-column fixed="right" label="操作" width="150">
                                <template slot-scope="scope">
                                    <el-button @click="edit(scope.row)" type="text" size="small">编辑</el-button>
                                    <el-button @click="del(scope.row)" type="text" size="small" style="color: red;">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <#include "/lx/admin/components/page.html" />
                        <el-dialog title="编辑大学" :visible.sync="dialogVisible">
                            <el-form :model="form">
                                <el-form-item label="大学名称" label-width="100px">
                                    <el-input v-model="form.cnSchoolName" autocomplete="off" placeholder="请输入大学名称"></el-input>
                                </el-form-item>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogVisible = false">取 消</el-button>
                                <el-button type="primary" @click="updateCnSchool">确 定</el-button>
                            </div>
                        </el-dialog>
                    </template>
                </el-main>
            </el-container>
        </el-container>
        <#include "/lx/admin/components/footer.html" />
    </div>
    <#include "/lx/admin/components/scripts.html" />
    <script>
        var vue = new Vue({
        el: '#app',
        data() {
            return {
                list: [],
                keyword: '${keyword!}',
                dialogVisible: false,
                form: {
                    cnSchoolId: '',
                    cnSchoolName: ''
                }
            }
        },
        mounted: function() {
        },
        methods: {
            add() {
                // window.location.href = "/lx/admin/school/info";
                var self = this;
                self.form.cnSchoolId = '';
                self.form.cnSchoolName = '';
                self.dialogVisible = true;
            },
            edit(item) {
                // window.location.href = "/lx/admin/school/info?schoolId=" + item.id;
                var self = this;
                self.form.cnSchoolId = item.id;
                self.form.cnSchoolName = item.name;
                self.dialogVisible = true;
            },
            updateCnSchool() {
                var self = this;
                if (!self.form.cnSchoolName) {
                    msg("大学名称不能为空");
                    return;
                }
                var url = "/lx/admin/school/submitCnSchool"
                var param = {
                    cnSchoolId: self.form.cnSchoolId,
                    name: self.form.cnSchoolName
                };
                var success = () => {
                    window.location.href = "/lx/admin/school/cnSchoolList";
                }
                var fail = (response) => {
                    msg(response.msg);
                }
                var complete = () => {
                    self.dialogVisible = false;
                }
                axiosRequestPro(url, param, success, fail, complete);
            },
            del(item) {
                var self = this;
                confirm("确认删除？请谨慎操作", "确认", function() {
                    var url = "/lx/admin/school/deleteCnSchool"
                    var param = {
                        cnSchoolId: item.id
                    };
                    var success = () => {
                        window.location.href = "/lx/admin/school/cnSchoolList";
                    }
                    var fail = (response) => {
                        msg(response.msg);
                    }
                    var complete = () => {}
                    axiosRequestPro(url, param, success, fail, complete);
                })
            },
            onSearch() {
                var self = this;
                var keys = [
                    { key: 'keyword', value: self.keyword }
                ]
                goPage(1, keys);
            },
            onPageChange(val) {
                // console.log('当前页: {val}' + val);
                goPage(val)
            }
        }
    })
    </script>
    <script>
        vue.list = ${items!}
    </script>
    <#include "/lx/admin/components/msg.html" />
    <style type="text/css">
    .title {
        font-size: 18px;
        font-weight: bold;
    }

    .operations {
        text-align: right;
    }
    </style>
</body>

</html>